import UserAPI from "@/api/user";
import RoleAPI from "@/api/role";
import type { UserPageQuery } from "@/api/user";
import type { IContentConfig } from "@/components/CURD/types";

const contentConfig: IContentConfig<UserPageQuery> = {
  pageName: "sys:user",
  table: {
    border: true,
    highlightCurrentRow: true,
  },
  pagination: {
    background: true,
    layout: "prev,pager,next,jumper,total,sizes",
    pageSize: 20,
    pageSizes: [10, 20, 30, 50],
  },
  indexAction: function (params) {
    if ("createAt" in params) {
      const createAt = params.createAt as string[];
      if (createAt?.length > 1) {
        params.startTime = createAt[0];
        params.endTime = createAt[1];
      }
      delete params.createAt;
    }
    return UserAPI.getPage(params);
  },
  deleteAction: UserAPI.deleteByIds,
  importAction(file) {
    return UserAPI.import(1, file);
  },
  exportAction: UserAPI.export,
  importTemplate: UserAPI.downloadTemplate,
  importsAction(data) {
    // 模拟导入数据
    console.log("importsAction", data);
    return Promise.resolve();
  },
  exportsAction: async function (params) {
    // 模拟获取到的是全量数据
    const res = await UserAPI.getPage(params);
    console.log("exportsAction", res.list);
    return res.list;
  },
  pk: "id",
  toolbar: [
    // "add",
    // "delete",
    // "import",
    // "export",
    // {
    //   name: "custom1",
    //   icon: "plus",
    //   text: "自定义1",
    //   auth: "import",
    //   type: "info",
    // },
  ],
  defaultToolbar: [],
  cols: [
    { type: "selection", width: 50, align: "center" },
    { label: "创建时间", align: "center", prop: "createdAt", width: 180 },
    {
      label: "商家编号\n商家分类",
      templet: "custom",
      slotName: "custom",
      align: "center",
      width: 180,
      prop: "storeCode|cid",
    },
    {
      label: "商家logo\n商家名称",
      align: "center",
      width: 180,
      prop: "avatar",
      templet: "custom",
      slotName: "test",
    },
    {
      label: "渠道名称\n渠道编号",
      align: "center",
      width: 180,
      prop: "username|nickname",
      slotName: "custom",
      templet: "custom",
    },
    {
      label: "商务名称\n商务编号",
      align: "center",
      width: 180,
      prop: "u|1",
      slotName: "custom",
      templet: "custom",
    },
    { label: "所属地区", align: "center", width: 180, prop: "1" },
    {
      label: "联系人姓名\n联系人电话",
      align: "center",
      width: 180,
      prop: "managerName|managerTel",
      slotName: "custom",
      templet: "custom",
    },
    {
      label: "商家状态",
      align: "center",
      width: 180,
      prop: "reviewStatus",
      templet: "custom",
      slotName: "status",
    },

    {
      label: "操作",
      align: "center",
      fixed: "right",
      width: 220,
      templet: "tool",
      operat: [
        "edit",
        {
          name: "reset_pwd",
          auth: "password:reset",
          icon: "refresh-left",
          text: "聚合支付",
        },
        {
          name: "config",
          auth: "password:reset",
          icon: "refresh-right",
          text: "平台设置",
        },
      ],
    },
  ],
};

export default contentConfig;
